var vm = new Vue({
    el:'#rrapp',
    data:{
      collageData:null,
      yearData:null,
      termData:null,
      weekData:null,
      dayData:null,
      indexData:null,
      collageValue:[],
      yearValue:[],
      termValue:[],
      weekValue:[],
      dayValue:[],
      indexValue:[],
      collageOptions:[],
      yearOptions:[],
      termOptions:[],
      weekOptions:[],
      dayOptions:[],
      indexOptions:[]
    },
    mounted(){
         $.ajax({
            url: baseURL + "/college/getAllcollege",
            data: {},
            success: function (r) {
                for (i = 0; i < r.list.length; i++) {
                    var tempJson={
                        'value':r.list[i].collegeName,
                        'label':r.list[i].collegeName
                    }
                    vm.collageOptions.push(tempJson)
                }
            }
        });
        $.ajax({
            url: baseURL + "/term/getSchoolTerm",
            data: {},
            success: function (r) {
                for (i = 0; i < r.list.length; i++) {
                     var tempJson={
                        'value':r.list[i].schoolAcademicYear,
                        'label':r.list[i].schoolAcademicYear
                    }
                    vm.yearOptions.push(tempJson)
                }
            }
         });
         var listTerm=["1","2"];
         for (i = 0; i < listTerm.length; i++) {
            var tempJson={
                'value':listTerm[i],
                'label':"第"+listTerm[i]+"学期"
            }
            this.termOptions.push(tempJson)
         }
         for (i = 1; i < 21; i++) {
            var tempJson={
                'value':i,
                'label':"第"+i+"周"
            }
            this.weekOptions.push(tempJson)
         }
         for (i = 1; i < 8; i++) {
           var tempJson={
                'value':i,
                'label':"星期"+i
            }
            this.dayOptions.push(tempJson)
         }
         for (i = 1; i < 11; i+=2) {
            var tempJson={
                'value':i,
                'label':"第"+i+"节"
            }
            this.indexOptions.push(tempJson)
         }
    },
    methods:{

    }
});
   //*******************************v**u**e*****************************************//
var studentAttendenceCollage = echarts.init(document.getElementById('studentAttendenceCollage'),'');
var studentAttendenceCollage1 = echarts.init(document.getElementById('studentAttendenceCollage1'),'');
option = {
    title: {
        text: '学院教师有课率',
        left:'center'
    },
    tooltip: {
    },
    legend: {
        data:['有课率']
    },
    toolbox: {
    },
    xAxis:  {
        type: 'category',
        data: ['','','','','','','','','','',''],
        axisLabel: {
            interval:0,
            rotate:40
        }
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} %'
        }
    },
    series: [
        {
            name:'有课老师占比',
            type:'bar',
            data:[100,100,100,100,100,100,100,100,100,100],
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }
    ]
};
option1 = {
    title: {
        text: '学院教师有课占比',
    },
    tooltip: {
    },
    legend: {
        data:['有课教师数','无课教师数']
    },
    toolbox: {
    },
    xAxis:  {
        type: 'category',
        data: ['','','','','','','','','','',''],
        axisLabel: {
            interval:0,
            rotate:40
        }
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} (数量)'
        }
    },
    series: [
        {
            name:'有课教师数',
            type:'bar',
            stack: '总量',
            data:[100,100,100,100,100,100,100,100,100,100],
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        },
        {
            name:'无课教师数',
            type:'bar',
            stack: '总量',
            data:[100,100,100,100,100,100,100,100,100,100],
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }
    ]
};
window.onresize = function(){
    studentAttendenceCollage.resize()
    studentAttendenceCollage1.resize()
}
$(function () {
    setDate('3')

});
function goString(data){
    var temp=""
    for(let i in data){
        if(i==data.length-1){
            temp+=('\''+data[i]+'\'')
        }else{
            temp+=('\''+data[i]+'\'')+','
        }
    }
    return temp
}
function query() {
    loadOption();
}
function getSeries(data)
{
    var     series=
    {
        name:'有课率',
        type:'bar',
        data:data,
        barWidth : 20//柱图宽度
    }
    return series;
}
function getSeriesList(data0,data1)
{
  var  series=[
        {
            name:'有课教师数',
            type:'bar',
            stack: '总量',
            data:data0
        },
        {
            name:'无课教师数',
            type:'bar',
            stack: '总量',
            data:data1
        }
    ]
    return series;
}


function loadOption(){
    vm.collageData=goString(vm.collageValue);
    vm.yearData=goString(vm.yearValue);
    vm.termData=goString(vm.termValue);
    vm.weekData=goString(vm.weekValue);
    vm.dayData=goString(vm.dayValue);
    vm.indexData=goString(vm.indexValue);
    $.ajax({
        url : baseURL + "/TeacherEvaluationCharts/getCollegeTeacheingRanking",
        data : {
            "collegeName":vm.collageData,
            "academicYear":vm.yearData,
            "academicTerm":vm.termData,
            "academicWeek":vm.weekData,
            "academicDay":vm.dayData,
            "academicIndex":vm.indexData,
            "startDate":$("#startDate").val(),
            "endDate":$("#endDate").val()
        },
        dataType : "json",
        success : function(result) {

            option.xAxis.data=result.option.collageName;
            option.series=getSeries(result.option.collageRate);
            studentAttendenceCollage.setOption(option,true);
            option1.xAxis.data=result.option.collageName;
            option1.series=getSeriesList(result.option.teachingTeacherTotals,result.option.noTeachingTeacherTotals);
            studentAttendenceCollage1.setOption(option1,true);

        },
        error : function(errorMsg) {
            //请求失败时执行该函数
            alert("图表请求数据失败!");
            studentNonAttendenceChart.hideLoading();
        }

    })
};